﻿
// 2023/2/28: 首个版本

using System;
using ASEva;
using ASEva.UIEto;
using Eto.Forms;

namespace CommonSource
{
    class CommonPickOptionsControl : Panel
    {
        public CommonPickOptionsControl(bool withEvent)
        {
            var layout = this.SetContentAsColumnLayout(0, 8);
            var groupBus = layout.AddGroupBox(chinese ? "总线通道筛选" : "Bus Channel Filter", true);
            var groupVideo = layout.AddGroupBox(chinese ? "视频通道筛选" : "Video Channel Filter", true);
            var groupOthers = layout.AddGroupBox(chinese ? "其他数据筛选" : "Other Data Filter");

            var layoutBus = groupBus.SetContentAsTableLayout(4, 8, 4);
            for (int i = 0; i < 2; i++)
            {
                var row = layoutBus.AddRow();
                for (int j = 0; j < 8; j++)
                {
                    checkBus[i * 8 + j] = row.AddCheckBox("CH" + (i * 8 + j + 1), true, false, true);
                }
            }

            var layoutVideo = groupVideo.SetContentAsTableLayout(4, 8, 4);
            for (int i = 0; i < 2; i++)
            {
                var row = layoutVideo.AddRow();
                for (int j = 0; j < 12; j++)
                {
                    checkVideo[i * 12 + j] = row.AddCheckBox(((char)('A' + i * 12 + j)).ToString(), true, false, true);
                }
            }

            var layoutOthers = groupOthers.SetContentAsRowLayout();
            checkAudio = layoutOthers.AddCheckBox(chinese ? "音频" : "Audio", false, true);
            checkSignal = layoutOthers.AddCheckBox(chinese ? "信号" : "Signal", false, true);
            checkSample = layoutOthers.AddCheckBox(chinese ? "样本" : "Sample", false, true);
            checkMatrix = layoutOthers.AddCheckBox(chinese ? "矩阵" : "Matrix", false, true);
            if (withEvent) checkEvent = layoutOthers.AddCheckBox(chinese ? "事件" : "Event", false, true);
        }

        public CommonPickOptions Options
        {
            get
            {
                var options = new CommonPickOptions();

                options.BusChannelFilter = new bool[16];
                for (int i = 0; i < 16; i++) options.BusChannelFilter[i] = checkBus[i].Checked.Value;

                options.VideoChannelFilter = new bool[24];
                for (int i = 0; i < 24; i++) options.VideoChannelFilter[i] = checkVideo[i].Checked.Value;

                options.AudioFilter = checkAudio.Checked.Value;
                options.SignalFilter = checkSignal.Checked.Value;
                options.SampleFilter = checkSample.Checked.Value;
                options.MatrixFilter = checkMatrix.Checked.Value;
                options.EventFilter = checkEvent == null ? false : checkEvent.Checked.Value;

                return options;
            }
        }

        private bool chinese = Agency.GetAppLanguage() == "ch";

        private CheckBox[] checkBus = new CheckBox[16];
        private CheckBox[] checkVideo = new CheckBox[24];
        private CheckBox checkAudio, checkSignal, checkSample, checkMatrix, checkEvent;
    }
}
